package com.car.loan.framework.aspectj.impl;

import com.car.loan.common.enums.LoanStatusEnum;
import com.car.loan.common.utils.StringUtils;
import com.car.loan.framework.aspectj.DataStatusSqlService;
import com.car.loan.project.xr.util.bo.business.LoanBaseInfo;
import com.car.loan.project.xr.util.enums.DataAuditStatus;
import com.car.loan.project.xr.util.enums.FileAuditStatus;
import com.car.loan.project.xr.util.enums.InsuranceInfoStatus;
import com.car.loan.project.xr.util.enums.LoanBusinessAuditStatus;
import com.car.loan.project.xr.util.enums.MortgageInfoStatus;
import com.car.loan.project.xr.util.enums.PaymentInfoStatus;
import com.car.loan.project.xr.util.enums.RepaymentInfoStatus;
import org.springframework.stereotype.Service;

/**
 * @author huangding
 * @description 业务状态
 * @date 2019/11/9 16:07
 */
@Service
public class FileAuditStatusSqlServiceImpl implements DataStatusSqlService {

    @Override
    public LoanStatusEnum getLoanStatusEnum() {
        return LoanStatusEnum.FILE_AUDIT_STATUS;
    }

    @Override
    public LoanBaseInfo getStatusRemark(LoanBaseInfo loanBaseInfo) {
        Long fileAuditStatus = loanBaseInfo.getFileAuditStatus();
        String statusRemark = StringUtils.EMPTY;
        if (FileAuditStatus.INIT.status == fileAuditStatus) {
            statusRemark = "待审核";
        } else if (FileAuditStatus.SUBMIT.status == fileAuditStatus) {
            statusRemark = "已审核";
        }
        loanBaseInfo.setStatusRemark(statusRemark);
        return loanBaseInfo;
    }

    /**
     * 注：状态为待审核（默认）、已审核 资料审核、付款信息、保险信息、抵押信息、还款信息完成后产生， 档案审核提交后，一直展示
     *
     * @param statusAlias 表名
     * @param status 列表状态
     */
    @Override
    public String getSql(String statusAlias, Integer status) {
        String sql = " {}.repayment_info_status = " + RepaymentInfoStatus.SUBMIT.status
            + " and {}.mortgage_info_status = " + MortgageInfoStatus.SUBMIT.status
            + " and {}.insurance_info_status = " + InsuranceInfoStatus.SUBMIT.status
            + " and {}.payment_info_status = " + PaymentInfoStatus.SUBMIT.status
            + " and {}.data_audit_status = " + DataAuditStatus.SUBMIT.status;
        if (status != null) {
            sql += " and {}.file_audit_status =  " + status;
        }
        return sql.replace("{}", statusAlias);
    }

    @Override
    public String getSortSql(String statusAlias) {
        return " order by loan.id  desc";
    }

}
